package com.joysuch.wwyt.datadump.biz.processor;

import cn.zlg.common.datadump.annotation.DataDumpEntity;
import cn.zlg.common.datadump.processor.BaseImportEntityProcessor;
import com.joysuch.wwyt.datadump.biz.model.RiskDistrictDumpBean;
import com.joysuch.wwyt.risk.entity.RiskDistrict;
import com.joysuch.wwyt.risk.entity.RiskEvaluationControl;
import com.joysuch.wwyt.risk.entity.RiskPointEvaluationBusiness;
import com.joysuch.wwyt.risk.repository.RiskDistrictDao;
import com.joysuch.wwyt.risk.repository.RiskEvaluationControlDao;
import com.joysuch.wwyt.risk.repository.RiskPointEvaluationBusinessDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @Author ZhaoQiuWei
 * @Date 2021/12/20 16:38
 */
@Component
public class RiskDistrictImportProcessor extends BaseImportEntityProcessor<RiskDistrictDumpBean, RiskDistrict> {

    @Autowired
    private RiskDistrictDao riskDistrictDao;
    @Autowired
    private RiskEvaluationControlDao controlDao;

    @Override
    public RiskDistrict processBeforePersist(RiskDistrictDumpBean origin, RiskDistrict entity, DataDumpEntity annotation, boolean override) {
//        if (entity.getId() != null) {
//            Assert.isTrue(riskDistrictDao.countOfNameExcludeId(entity.getName(), entity.getId()) == 0,
//                    String.format("名称[%s]已存在", entity.getName()));
//        } else {
//            Assert.isTrue(riskDistrictDao.countOfName(entity.getName()) == 0, String.format("名称[%s]已存在", entity.getName()));
//        }
//        RiskEvaluationControl control = controlDao.findByName("风险四色图计算逻辑");
//        if (control != null && control.getSwitchState() == 0) {
//            if (entity.getEvaluationState() == null || entity.getEvaluationState().equals(0)) {
//                entity.setRealTimeRiskLevel(entity.getRiskLevel());
//            }
//        } else if (control == null || control.getSwitchState() == 1) {
//            if (entity.getId() != null) {
//                if (entity.getEvaluationState() != null || entity.getEvaluationState().equals(1)) {
//                    throw new IllegalArgumentException("该区域已有评估内容,请在页面上修改");
//                }
//                entity.setRealTimeRiskLevel(entity.getRiskLevel());
//            } else {
//                entity.setRealTimeRiskLevel(entity.getRiskLevel());
//            }
//        }
//        entity.setOwnLevel(entity.getRiskLevel());
        return entity;
    }
}
